#include <iostream>
#include <string>
#include <fstream>
#include "bundle.h"

int main(int argc, char *argv[])
{
    std::cout << "argv[1]是源文件的路径名称\n";
    std::cout << "argv[2]是压缩后的路径名称\n";
    std::string ifilename = argv[1];
    std::string ofilename = argv[2];

    std::ifstream ifs;
    // 打开源文件夹
    ifs.open(ifilename, std::ios::binary);
    // 跳转读写位置到末尾
    ifs.seekg(0, std::ios::end);
    // 获取末尾偏移量---文件长度
    size_t fsize = ifs.tellg();
    // 跳转到文件起始
    ifs.seekg(0, std::ios::beg);

    std::string body;
    body.resize(fsize);
    // 读取文件所有数据到body
    ifs.read(&body[0], fsize);

//进行文件压缩
    std::string packed = bundle::pack(bundle::LZIP, body);

    std::ofstream ofs;
    ofs.open(ofilename, std::ios::binary);
    ofs.write(&packed[0], packed.size());

    ifs.close();
    ofs.close();
    return 0;
}